package com 
{
	import flash.events.Event;
	/**
	 * ...
	 * @author Matthew Ladouceur
	 */
	public class ClassInput extends flaInputText
	{
		private var _dictionary:Vector.<String> = new Vector.<String>();
		
		private var ac:AutoComplete;
		private var userInputLength:Number = 0;
		
		public function ClassInput() 
		{
			super();
			
			_dictionary.push("Mercenary");
			_dictionary.push("Ranger");
			_dictionary.push("Templar");
			_dictionary.push("Assassin");
			_dictionary.push("Nightblade");
			_dictionary.push("Witch Hunter");
			_dictionary.push("Druid");
			_dictionary.push("Mage");
			_dictionary.push("Bard");
			
			ac = new AutoComplete(_text, _dictionary);
			ac.charBuffer = 1;
			ac.parseDelay = 50;
			ac.addEventListener(Event.CHANGE, onChange);
		}
		
		private function onChange(e:Event):void {
			if (_text.text.length > userInputLength){
				userInputLength = _text.text.length;
				if (ac.completions.length > 0){
					_text.text = _text.text.concat(ac.completions[0].slice(userInputLength));
					_text.setSelection(userInputLength, _text.text.length);
				}
			}else {
				userInputLength = _text.text.length;
			}
			
			dispatchEvent(e);
		}
		
	}

}